package com.sunchangming.rpcgen;

public class TypeString extends Type {

	@Override
	public String getName(Variable variable) {
		return "String";
	}

	@Override
	public String getMarshalStr(Variable v, String osname) {
		return String.format("%s.writeUTF(%s)", osname, v.getName());
	}

	@Override
	public String getUnmarshalStr(Variable v, String osname, boolean useThis) {
		return String.format((useThis ? "this." : "") + "%s=%s.readUTF()", v.getName(), osname);
	}

	@Override
	public String getBoxName() {
		return "String";
	}

	@Override
	public String getDefaultValue(Variable variable) {
		final String userstr = variable.defaultvalue;
		if (userstr != null && !userstr.isEmpty()) {
			return "\"" + userstr + "\"";
		}
		return "\"\"";
	}

	@Override
	public String getHashCodeStr(Variable variable) {
		return "this." + variable.getName() + ".hashCode()";
	}

	@Override
	public String getFromSqlStr(Variable variable, String string) {
		return String.format("this.%s=%s.getString(\"%s\")", variable.getName(), string, variable.getFrom());
	}

}
